package com.seelyn.rhea.mvc.render.provider;

import com.seelyn.rhea.mvc.context.Request;
import com.seelyn.rhea.mvc.context.Response;
import com.seelyn.rhea.mvc.render.Render;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import java.io.IOException;

/**
 * @author linfeng
 * @since 2016/1/20
 */
public class JspRender implements Render<JspView> {

    @Override public void render(JspView jspView, Request request, Response response) {
        String url = jspView.getPath();
        try {
            RequestDispatcher requestDispatcher = request.raw().getRequestDispatcher(url);
            requestDispatcher.forward(request.raw(), response.raw());
        } catch (ServletException | IOException e) {
            throw new RuntimeException("Could not forward the JSP response for path=" + url, e);
        }
    }

}
